package youcaihuaoa.weetop.com.vm.main

import android.app.Application
import androidx.databinding.ObservableField
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.configs.AppConstants
import com.robot.base.configs.PrefsManager
import com.robot.base.model.WagesProfileItemBean
import com.robot.base.util.arouter.ARouterUtil.goToActivity
import me.goldze.mvvmhabit.binding.command.BindingAction
import me.goldze.mvvmhabit.binding.command.BindingCommand
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent

class BasicInfoViewModel(application: Application) : GLBaseViewModel(application) {
    val headUrl = ObservableField<String>()
    val rlImg = ObservableField<String>()
    val sfzzm_image = ObservableField<String>()
    val sfzbm_image = ObservableField<String>()
    val xlzs_image = ObservableField<String>()
    val xwzs_image = ObservableField<String>()
    val htfj_image = ObservableField<String>()
    val uiEvent = UIEvent()

    class UIEvent {
        val menuDataLiveEvent = SingleLiveEvent<MutableList<WagesProfileItemBean>>()
    }

    val toLogoutCommand = BindingCommand<Any>(BindingAction {
        PrefsManager.clear()
        goToActivity(AppConstants.Router.Main.A_LOGIN)
    })

    fun initData() {
        val userInfo = PrefsManager.getUserInfo()
        headUrl.set(userInfo.head_img)
        rlImg.set(userInfo.rl_img)
        sfzzm_image.set(userInfo.sfzzm_image)
        sfzbm_image.set(userInfo.sfzbm_image)
        xlzs_image.set(userInfo.xlzs_image)
        xwzs_image.set(userInfo.xwzs_image)
        htfj_image.set(userInfo.htfj_image)

        val menu1 = mutableListOf(
            WagesProfileItemBean().apply {
                title = "工号："
                content = userInfo.job_number ?: ""
            }, WagesProfileItemBean().apply {
                title = "姓名："
                content = userInfo.user_name ?: ""
            }, WagesProfileItemBean().apply {
                title = "性别："
                content = userInfo.sex ?: ""
            }, WagesProfileItemBean().apply {
                title = "手机号："
                content = userInfo.phone ?: ""
            }, WagesProfileItemBean().apply {
                title = "所属公司："
                content = userInfo.company_name ?: ""
            }, WagesProfileItemBean().apply {
                title = "所属部门："
                content = userInfo.department_name ?: ""
            }, WagesProfileItemBean().apply {
                title = "所属职位："
                content = userInfo.job_name ?: ""
            }, WagesProfileItemBean().apply {
                title = "入职时间："
                content = userInfo.rz_time ?: ""
            }, WagesProfileItemBean().apply {
                title = "员工类型："
                content = userInfo.yglx_data ?: ""
            }, WagesProfileItemBean().apply {
                title = "试用期天数："
                content = userInfo.syq_time ?: ""
            }, WagesProfileItemBean().apply {
                title = "转正日期："
                content = userInfo.zzrq_time ?: ""
            }, WagesProfileItemBean().apply {
                title = "基本工资："
                content = userInfo.jbgz_price ?: ""
            }, WagesProfileItemBean().apply {
                title = "绩效工资："
                content = userInfo.jxgz_price ?: ""
            }, WagesProfileItemBean().apply {
                title = "是否转正："
                content = if (userInfo.zz_status == "1") {
                    "是"
                } else {
                    "否"
                }
            }, WagesProfileItemBean().apply {
                title = "在职状态："
                content = if (userInfo.status == "1") {
                    "在职"
                } else {
                    "离职"
                }
            }, WagesProfileItemBean().apply {
                title = "证件号码："
                content = userInfo.zjhm_number ?: ""
            }, WagesProfileItemBean().apply {
                title = "民族"
                content = userInfo.mz_data ?: ""
            }, WagesProfileItemBean().apply {
                title = "年龄"
                content = userInfo.age ?: ""
            }, WagesProfileItemBean().apply {
                title = "婚姻状况"
                content = userInfo.hyzk_data ?: ""
            }, WagesProfileItemBean().apply {
                title = "籍贯"
                content = userInfo.jg_data ?: ""
            }, WagesProfileItemBean().apply {
                title = "学历"
                content = userInfo.xl_data ?: ""
            }, WagesProfileItemBean().apply {
                title = "毕业院校"
                content = userInfo.byyx_data ?: ""
            }, WagesProfileItemBean().apply {
                title = "毕业时间"
                content = userInfo.bysj_data ?: ""
            }, WagesProfileItemBean().apply {
                title = "所学专业"
                content = userInfo.syzy_data ?: ""
            }, WagesProfileItemBean().apply {
                title = "银行卡号"
                content = userInfo.yhkh_number ?: ""
            }, WagesProfileItemBean().apply {
                title = "开户行"
                content = userInfo.khh_data ?: ""
            }
        )
        uiEvent.menuDataLiveEvent.postValue(menu1)
    }
}